package com.ae.controller;

import com.ae.pojo.Admin;
import com.ae.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @Auther ys
 * * @Date 2020/0/21
 * 17:11
 */
@Controller
@RequestMapping("admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("loginView")
    public String loginView() {
        return "/behind/login.jsp";
    }

    @ResponseBody
    @RequestMapping("login")
    public String Login(Admin admin, HttpSession session) {

        String username = admin.getUsername();

        Admin admin1 = adminService.selectByUsername(username);

        if (admin1 != null) {

            if (admin.getPassword().equals(admin1.getPassword())) {

                session.setAttribute("admin",admin1);
                return "success";
            }
        }

        return null;
    }

    @RequestMapping("exit")
    public String exit(HttpSession session) {

        session.removeAttribute("admin");

        return "redirect:/admin/loginView";
    }


}
